package com.seele.tigerwallet.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class AssetsScrollView extends ScrollView {

    private int lastX;
    private int lastY;

    public AssetsScrollView(Context context) {
        this(context, null);
    }

    public AssetsScrollView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AssetsScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        //获取到手指处的横坐标和纵坐标
        int x = (int) event.getX();
        int y = (int) event.getY();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastX = x;
                lastY = y;
                break;
            case MotionEvent.ACTION_MOVE:

                int offX = x - lastX;
                int offY = y - lastY;
                if (y <= lastY && getTop() >= -213) {

                    layout(getLeft(), getTop() + offY, getRight(), getBottom() + offY);

                }


                //调用layout方法来重新放置它的位置
                break;
        }
        return true;
    }
}
